<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    /**
     * 1、boolean向数字类型转换时，true会转换成1，false会转换成0
     * 2、undefined转换为数字，结果为NaN
     * 3、null转换为数字，结果为0
     * 4、可以使用parseInt parseFloat Number来实现
     *    将字符串类型转换为数字类型，如果字符串是一个非纯数字
     *    字符的字符串，转换结果就是NaN
     */
    var b1 = true;
    var b2 = false;
    var result1 = b1 + 0;
    var result2 = b2 + 0;
    console.log(result1, result2);


    var u1 = undefined;
    var result3 = Number(u1);
    console.log(result3);

    var n1 = null;
    var result4 = Number(null);
    console.log(result4);


    var str1 = "123";
    var str2 = "abc123";

    var result5 = parseInt(str1);
    console.log(result5);
    var result6 = parseInt(str2);
    console.log(result6);
</script>
</html>